import os, distutils.spawn
vars = Variables('.SConstruct')
vars.Add(PathVariable('sherpa','path to sherpa',
    os.popen('Sherpa-config --prefix').read().rstrip() if
    distutils.spawn.find_executable('Sherpa-config') else
    '/path/to/sherpa',PathVariable.PathIsDir))

env = Environment(variables=vars,CPPPATH=['${sherpa}/include/SHERPA-MC'])

vars.Add('CXX','The C++ Compiler',
    os.popen(env['sherpa']+'/bin/Sherpa-config --cxx').read().rstrip())
vars.Add('CXXFLAGS','The C++ Flags',['-g','-O2', '-std=c++11'])
vars.Update(env)
Help(vars.GenerateHelpText(env))
vars.Save('.SConstruct',env)

env['ENV']['PATH']=os.environ['PATH']
if env['PLATFORM']=='darwin':
   env.Append( LINKFLAGS='-Wl,-undefined -Wl,dynamic_lookup' )
   if os.environ.has_key('DYLD_LIBRARY_PATH'):
      env['ENV']['DYLD_LIBRARY_PATH']=os.environ['DYLD_LIBRARY_PATH']
else:
   if os.environ.has_key('LD_LIBRARY_PATH'):
      env['ENV']['LD_LIBRARY_PATH']=os.environ['LD_LIBRARY_PATH']

env['ENV']['PATH']=os.environ['PATH']
if env['PLATFORM']=='darwin':
   env.Append( LINKFLAGS='-Wl,-undefined -Wl,dynamic_lookup' )
   if os.environ.has_key('DYLD_LIBRARY_PATH'):
      env['ENV']['DYLD_LIBRARY_PATH']=os.environ['DYLD_LIBRARY_PATH']
else:
   if os.environ.has_key('LD_LIBRARY_PATH'):
      env['ENV']['LD_LIBRARY_PATH']=os.environ['LD_LIBRARY_PATH']

env.SharedLibrary('SherpaWbb', ['Wbb_Virtual.f', 'Wbb_Interface.C'])
